﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace UpdaterForm
{
    [Serializable]
    public class History
    {
        public History()
        {
            Logs = new List<UpdateLog>();
        }

        [XmlElement("Log")]
        public List<UpdateLog> Logs { get; set; }

        public bool Contains(string name)
        {
            return Logs.Any(log => log.Name.Equals(name));
        }

        public UpdateState GetStatus(string p)
        {
            if (Contains(p))
            {
                return Logs.Last(log => log.Name.Equals(p)).State;
            }
            return UpdateState.RecentlyAdded;
        }

        public UpdateLog GetLog(string p)
        {
            UpdateLog updateLog = null;
            try
            {
                updateLog = Logs.Last(log => log.Name.Equals(p));
            }
            catch (Exception)
            {
            }
            return updateLog;
        }
    }
}